<!-- 
@name: 首页
-->
<template>
	<div id="BankingBusinessList" class="page">
		<div class="content-wrap">
			<div class="diy-area">
				<div class="like">
					<div class="type2" v-if="listModel" ref='type2Scorll' id='type2Scorll'>
						<van-list v-model="loading" offset='0' :finished="finished" finished-text="没有更多了" @load="onLoad">
							<div @click="goDetail(goodsItem)" class="item flex-row flex-center" v-for="(goodsItem, goodsIndex) in likeList" :key="goodsIndex">
								<div style="flex:1">
									<div class="text1">{{goodsItem.name}}</div>
									<div class="text4">{{goodsItem.summary}}</div>
								</div>
								<img object-fit="fill" :src="goodsItem.photo"></img>
							</div>
						</van-list>

					</div>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
export default {
	name: 'app',
	components: {},
	data() {
		return {
			searchValue: '',
			searchTypeIndex: '',
			getGtypeList: [],
			listModel: true, //true 列表模式 false 大图模式
			searchTypeList: [
				{ value: '销量最高', pkey: 'XS' },
				{ value: '距离最近', pkey: 'NEAR' },
				{ value: '评分最高', pkey: 'RATE' },
			],
			searchData: {
				sortType: 'XS', //XS 销量,NEAR 距离,RATE 评分
				page: 0,
				pagesize: 5,
				lng: '1',
				lat: '1',
			},
			likeList: [],
			activeName: '',
			loading: false,
			finished: false,
		};
	},

	created() {
		if (this.$route.query.pkey) {
			//跳转过来的分类pkey
			this.activeName = Number(this.$route.query.pkey);
		}
		this.getGtype_goods();
	},
	methods: {
		goDetail(item) {
			// console.log()
			this.$router.push({
				path: '/BankingBusiness/share',
				query: { pkey: item.pkey },
			});
		},
		sortChange(pkey) {
			this.searchData.sortType = pkey;
			this.clearSearch();
			this.finished = true;
			this.getData(true);
		},
		onLoad() {
			console.log('触底');
			this.getData();
		},
		onClick() {
			this.clearSearch();
			this.finished = true;
			this.getData(true);
		},
		getGtype_goods() {
			this.$myApi.getGtype_goods().then((res) => {
				if (res.code == 0) {
					var arr = [{ name: '全部', pkey: '' }, ...res.result];
					this.getGtypeList = arr;
				} else {
				}
			});
		},
		getData(finished) {
			// finished 避免清空列表出发刷新
			var params = this.searchData;
			params.gtype = this.activeName;
			this.$myApi.queryBookModel_book(params).then((res) => {
				if (res.code == 0) {
					this.likeList = [...this.likeList, ...res.result.content];
					this.loading = false;
					this.searchData.page++;
					if (finished) {
						this.finished = false;
					}
					if (res.result.content.length < 5) {
						this.finished = true;
					}
				} else {
				}
			});
		},
		clearSearch() {
			this.likeList = [];
			this.searchData.page = 0;
			this.searchData.pagesize = 5;
			this.finished = false;
		},
		onSearch(e) {
			console.log(e);
			this.clearSearch();
			this.searchData.title = e;
			this.finished = true;
			this.getData(true);
		},
		onCancel() {},
	},
};
</script>
<style lang="less" scoped>
#BankingBusinessList {
	padding-left: 0rem;
	padding-right: 0rem;
	min-height: 100vh;
	background-color: #fafafa;

	padding-bottom: 0;
	.van-swipe__indicators {
		bottom: 25px;
	}
	.van-search__content {
		border-radius: 20px;
	}
	.searchWrap {
		width: 100%;
	}
	.searchHistory {
		padding: 0.25rem;
		background-color: #fff;
		img {
			height: 0.28rem;
			width: 0.32rem;
		}
		.text1 {
			font-size: 0.28rem;
			font-weight: bold;
			color: #333333;
			margin-bottom: 0.2rem;
		}
		.text2 {
			background: #f5f5f5;
			border-radius: 5px;
			padding: 0.16rem 0.3rem;
			margin-right: 0.12rem;
			margin-bottom: 0.12rem;
			white-space: nowrap;
			display: inline-block;
			font-size: 0.24rem;
			color: #666666;
		}
		.text3 {
			.text2();
			color: #999999;
		}
	}
	.content-wrap {
		width: 100%;
		height: auto;
		.diy-area {
			// background-color: #fff;
			position: relative;
			background-color: inherit;

			img {
				vertical-align: top;
			}

			.banner {
				.bannerImg {
					height: 4rem;
					width: 100%;
				}
			}
			.br {
				height: 0.2rem;
				width: 100%;
				background: #fafafa;
			}
			.likeTitle {
				font-size: 0.32rem;
				font-family: PingFang SC;
				font-weight: bold;
				color: #000000;
				margin-bottom: 0.24rem;
				text-align: center;
			}
			.like {
				padding: 0.25rem;

				height: calc(100vh - 46px - 0.5rem);
				position: relative;
				box-sizing: border-box;
				border-radius: 10px;

				.button {
					background: #ffce17;
					border-radius: 20px;
					font-size: 0.26rem;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333;
					padding: 0.1rem 0.34rem;
					height: auto;
				}
				.type1 {
					width: 100%;
					overflow-x: scroll;
					height: 100%;
					padding-bottom: 1rem;
					img {
						height: 3rem;
						width: 100%;
						border-radius: 10px;
					}
					.item {
						margin-bottom: 8px;
						background: #fff;

						border-radius: 10px;
						.text1 {
							font-size: 0.3rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #000000;
							text-overflow: ellipsis;
							white-space: nowrap;
							overflow: hidden;
							margin-bottom: 0.2rem;
						}
						.text2 {
							font-size: 0.3rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #D95954;
						}
						.text3 {
							background: rgba(255, 212, 49, 0.12);
							border-radius: 2px;
							font-size: 0.24rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #D95954;
							padding: 0.07rem 0.17rem;
							margin-right: 0.23rem;
						}
						.text4 {
							font-size: 0.22rem;
							font-family: PingFang SC;
							font-weight: 500;
							color: #666666;
							margin-right: 0.23rem;
						}
					}
				}
				.type2 {
					width: 100%;
					overflow-x: scroll;
					height: 100%;
					padding-bottom: 1rem;
					img {
						height: 1.1rem;
						width: 1.1rem;
						margin-right: 0.24rem;
						border-radius: 5px;
					}
					.item {
						margin-bottom: 8px;
						background: #fff;
						padding: 0.24rem;
						border-radius: 10px;
						.text1 {
							font-size: 0.3rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #000000;
							display: -webkit-box;
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 2;
							overflow: hidden;
							margin-bottom: 0.2rem;
						}
						.text2 {
							font-size: 0.3rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #D95954;
						}
						.text3 {
							background: rgba(255, 212, 49, 0.12);
							border-radius: 2px;
							font-size: 0.24rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #D95954;
							padding: 0.07rem 0.17rem;
							margin-right: 0.23rem;
						}
						.text4 {
							font-size: 0.22rem;
							font-family: PingFang SC;
							font-weight: 500;
							color: #666666;
							margin-right: 0.23rem;
						}
					}
				}
			}
			.iconWrap {
				position: relative;
				padding-bottom: 0.55rem;
				border-radius: 20px 20px 0 0;
				top: -0.3rem;
				// margin-top: -0.4rem;
				background-color: #fafafa;
				z-index: 999;
				display: grid;
				grid-template-columns: repeat(4, 25%);
				.iconImg {
					width: 0.8rem;
					height: 0.8rem;
					margin-bottom: 0.12rem;
				}
				.item {
					-webkit-box-flex: 1;
					flex: 1;
					margin-top: 0.3rem;
					font-size: 0.24rem;
					text-align: center;
				}
			}
		}
	}
}
</style>
<style lang="less" scoped>
/deep/.van-search .van-cell {
	padding-top: 0.2rem;
	padding-bottom: 0.2rem;
	font-size: 0.28rem;
}
/deep/.van-tab {
	// flex: 0 1 auto;
	// width: 1rem;
	font-size: 0.3rem;
}
/deep/.van-tab--active {
	font-weight: bold;
	font-size: 0.32rem;
}
</style>